﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using Nemerle.Contrib;

using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Mvc;
using BLToolkit.Data.Linq;

using NRails.Dinner.Models;
using NRails.Macros;

namespace NRails.Dinner
{
  [DbUsage]
  public class RSVPController : Controller
  {
    [Authorize, AcceptVerbs(HttpVerbs.Post)]
    public Register(id : int) : ActionResult
    {
        when (!db.IsUserRegistered(User.Identity.Name, id))
        {
            def rsvp = RSVP();
            rsvp.AttendeeName = User.Identity.Name;
            rsvp.DinnerID = id;

            _ = db.Insert(rsvp);
        }
        Content("Thanks - we'll see you there!");
    }
  }
}
